~ chicken-core (chicken-5) /manual/Module (chicken base)
Trap1[[tags: manual]]
2[[toc:]]
3
4== Module (chicken base)
5
6Core procedures and macros, acting as basic extensions to the R5RS
7standard and other essential features.
8
9This module is used by default, unless a program is compiled with
10the {{-explicit-use}} option.
11
12=== Numeric predicates
13
14These allow you to make a more precise differentiation between number
15types and their properties, not provided by R5RS.
16
17==== fixnum?
18
19<procedure>(fixnum? X)</procedure>
20
21Returns {{#t}} if {{X}} is a fixnum, or {{#f}} otherwise.
22
23==== flonum?
24
25<procedure>(flonum? X)</procedure>
26
27Returns {{#t}} if {{X}} is a flonum, or {{#f}} otherwise.
28
29==== bignum?
30
31<procedure>(bignum? X)</procedure>
32
33Returns {{#t}} if {{X}} is a bignum (integer larger than fits in a
34fixnum), or {{#f}} otherwise.
35
36==== exact-integer?
37
38<procedure>(exact-integer? X)</procedure>
39
40Returns {{#t}} if {{X}} is an exact integer (i.e., a fixnum or a
41bignum), or {{#f}} otherwise.
42
43This procedure is compatible with the definition from the R7RS
44{{(scheme base)}} library.
45
46==== cplxnum?
47
48<procedure>(cplxnum? X)</procedure>
49
50Returns {{#t}} if {{X}} is a true complex number (it has an imaginary
51component), or {{#f}} otherwise.
52
53Please note that {{complex?}} will always return {{#t}} for any number
54type supported by CHICKEN, so you can use this predicate if you want
55to know the representational type of a number.
56
57==== ratnum?
58
59<procedure>(ratnum? X)</procedure>
60
61Returns {{#t}} if {{X}} is a true rational number (it is a fraction
62with a denominator that's not 1), or {{#f}} otherwise.
63
64Please note that {{rational?}} will always return {{#t}} for any
65number type supported by CHICKEN except complex numbers and non-finite
66flonums, so you can use this predicate if you want to know the
67representational type of a number.
68
69==== nan?
70
71<procedure>(nan? N)</procedure>
72
73Returns {{#t}} if {{N}} is not a number (a IEEE flonum NaN-value). If
74{{N}} is a complex number, it's considered nan if it has a real or
75imaginary component that's nan.
76
77This procedure is compatible with the definition from the R7RS
78{{(scheme inexact)}} library.
79
80==== infinite?
81
82<procedure>(infinite? N)</procedure>
83
84Returns {{#t}} if {{N}} is negative or positive infinity, and {{#f}}
85otherwise. If {{N}} is a complex number, it's considered infinite if
86it has a real or imaginary component that's infinite.
87
88This procedure is compatible with the definition from the R7RS
89{{(scheme inexact)}} library.
90
91==== finite?
92
93<procedure>(finite? N)</procedure>
94
95Returns {{#t}} if {{N}} represents a finite number and {{#f}}
96otherwise. Positive and negative infinity as well as NaNs are not
97considered finite. If {{N}} is a complex number, it's considered
98finite if both the real and imaginary components are finite.
99
100This procedure is compatible with the definition from the R7RS
101{{(scheme inexact)}} library.
102
103==== equal=?
104
105<procedure>(equal=? X y)</procedure>
106
107Similar to the standard procedure {{equal?}}, but compares numbers
108using the {{=}} operator, so {{equal=?}} allows structural comparison
109in combination with comparison of numerical data by value.
110
111
112=== Arithmetic
113
114==== add1/sub1
115
116<procedure>(add1 N)</procedure>
117<procedure>(sub1 N)</procedure>
118
119Adds/subtracts 1 from {{N}}.
120
121
122==== exact-integer-sqrt
123
124<procedure>(exact-integer-sqrt K)</procedure>
125
126Returns two values {{s}} and {{r}}, where {{s^2 + r = K}} and {{K < (s+1)^2}}.
127In other words, {{s}} is the closest square root we can find that's equal to or
128smaller than {{K}}, and {{r}} is the rest if {{K}} isn't a neat square of two numbers.
129
130This procedure is compatible with the definition from the R7RS
131{{(scheme base)}} library.
132
133==== exact-integer-nth-root
134
135<procedure>(exact-integer-nth-root K N)</procedure>
136
137Like {{exact-integer-sqrt}}, but with any base value. Calculates
138{{\sqrt[N]{K}}}, the {{N}}th root of {{K}} and returns two values
139{{s}} and {{r}} where {{s^N + r = K}} and {{K < (s+1)^N}}.
140
141
142==== Division with quotient and remainder
143
144<procedure>(quotient&remainder X Y)</procedure>
145<procedure>(quotient&modulo X Y)</procedure>
146
147Returns two values: the quotient and the remainder (or modulo) of
148{{X}} divided by {{Y}}. Could be defined as {{(values (quotient X Y)
149(remainder X Y))}}, but is much more efficient when dividing very
150large numbers.
151
152==== signum
153
154<procedure>(signum N)</procedure>
155
156For real numbers, returns {{1}} if {{N}} is positive, {{-1}} if {{N}}
157is negative or {{0}} if {{N}} is zero. {{signum}} is exactness
158preserving.
159
160For complex numbers, returns a complex number of the same angle but
161with magnitude 1.
162
163
164=== Weak pairs
165
166''Weak pairs'' behave identically to regular pairs, with one
167exception: the car value may be garbage collected. When that happens,
168it gets replaced with a sentinel "broken-weak-pointer" value.
169
170They are indistinguishable from regular pairs: {{car}}, {{cdr}}, etc
171all work on them, {{pair?}} returns true, etc. The {{WRITE}}
172representation is identical to regular pairs, so they will be read
173back as pairs. In other words, they have no read/write invariance.
174
175They're the same as regular pairs for all intents and purposes.
176However, there's a {{weak-pair?}} predicate which ''can'' distinguish
177between regular pairs and weak pairs.
178
179NOTE: Due to internal limitations, {{set-car!}} on a weak pair
180currently may cause it to hold onto the value for one more GC cycle in
181some situations.
182
183==== weak-cons
184
185<procedure>(weak-cons obj[1] obj[2])</procedure><br>
186
187Returns a newly allocated weak pair whose car is obj[1] and whose cdr
188is obj[2]. The pair is indistinguishable from normal pairs, except as
189noted above.
190
191 (weak-cons 'a '()) ===> (a)
192 (weak-cons '(a) '(b c d)) ===> ((a) b c d)
193 (weak-cons "a" '(b c)) ===> ("a" b c)
194 (weak-cons 'a 3) ===> (a . 3)
195 (weak-cons '(a b) 'c) ===> ((a b) . c)
196
197 (import (chicken gc))
198
199 (let* ((x '(a b))
200 (y (weak-cons x 'c)))
201 (gc #t)
202 (car x)) ===> (a b)
203
204 (let ((x (weak-cons '(a b) 'c)))
205 (gc #t)
206 (car x)) ===> #!bwp
207
208As the final two examples show, when something ''else'' still holds on
209to the value that's stored in the car of a weak pair, it will not be
210reclaimed. But if the value is ''only'' referenced by one or more
211weak pairs, it is reclaimed and the car of the weak pair is replaced
212with the ''broken-weak-pointer'' value {{#!bwp}}.
213
214<procedure>(weak-pair? obj)</procedure><br>
215
216This predicate returns {{#t}} if and only if {{obj}} is a weak pair.
217
218 (weak-pair? (weak-cons 'a '())) ===> #t
219 (weak-pair? (cons 'a '())) ===> #f
220 (weak-pair? (vector 'a '())) ===> #f
221
222<procedure>(bwp-object? obj)</procedure>
223
224This predicate returns {{#t}} if {{obj}} is the broken-weak-pointer
225value, otherwise {{#f}}.
226
227
228=== Lazy evaluation
229
230==== delay-force
231
232<macro>(delay-force <expression>)</macro><br>
233
234The expression {{(delay-force expression)}} is conceptually similar to
235{{(delay (force expression))}}, with the difference that forcing the
236result of {{delay-force}} will in effect result in a tail call to
237{{(force expression)}}, while forcing the result of
238{{(delay (force expression))}} might not.
239
240Thus iterative lazy algorithms that might result in a long series of
241chains of delay and force can be rewritten using delay-force to
242prevent consuming unbounded space during evaluation.
243
244This special form is compatible with the definition from the R7RS
245{{(scheme lazy)}} library.
246
247See the description of force under
248[[Module scheme#control-features|Control features]] in the "scheme"
249module documentation for a more complete description of delayed
250evaluation.
251
252For more information regarding the unbounded build-up of space, see
253the [[http://srfi.schemers.org/srfi-45/srfi-45.html|SRFI-45]]
254rationale.
255
256==== make-promise
257
258<procedure>(make-promise obj)</procedure>
259
260The make-promise procedure returns a promise which, when forced, will
261return {{obj}} . It is similar to {{delay}}, but does not delay its
262argument: it is a procedure rather than syntax. If {{obj}} is already
263a promise, it is returned.
264
265This procedure is compatible with the definition from the R7RS
266{{(scheme lazy)}} library.
267
268
269==== promise?
270
271<procedure>(promise? X)</procedure>
272
273Returns {{#t}} if {{X}} is a promise returned by {{delay}}, or
274{{#f}} otherwise.
275
276This procedure is compatible with the definition from the R7RS
277{{(scheme lazy)}} library.
278
279
280=== Input/Output
281
282==== current-error-port
283
284<procedure>(current-error-port [PORT])</procedure>
285
286Returns default error output port. If {{PORT}} is given, then that
287port is selected as the new current error output port.
288
289Note that the default error output port is not buffered. Use
290[[Module (chicken port)#set-buffering-mode!|{{set-buffering-mode!}}]]
291if you need a different behaviour.
292
293==== print
294
295<procedure>(print [EXP1 ...])</procedure>
296
297Outputs the optional arguments {{EXP1 ...}} using {{display}} and
298writes a newline character to the port that is the value of
299{{(current-output-port)}}. Returns {{(void)}}.
300
301==== print*
302
303<procedure>(print* [EXP1 ...])</procedure>
304
305Similar to {{print}}, but does not output a terminating newline
306character and performs a {{flush-output}} after writing its arguments.
307
308
309=== Interrupts and error-handling
310
311==== enable-warnings
312
313<procedure>(enable-warnings [BOOL])</procedure>
314
315Enables or disables warnings, depending on wether {{BOOL}} is true or
316false. If called with no arguments, this procedure returns {{#t}} if
317warnings are currently enabled, or {{#f}} otherwise. Note that this is
318not a parameter. The current state (whether warnings are enabled or
319disabled) is global and not thread-local.
320
321
322==== error
323
324<procedure>(error [LOCATION] [STRING] EXP ...)</procedure>
325
326Prints error message, writes all extra arguments to the value of
327{{(current-error-port)}} and invokes the current
328exception-handler. This conforms to
329[[http://srfi.schemers.org/srfi-23/srfi-23.html|SRFI-23]]. If
330{{LOCATION}} is given and a symbol, it specifies the ''location'' (the
331name of the procedure) where the error occurred.
332
333
334==== assert
335
336<macro>(assert EXP [OBJ ...])</macro>
337
338Evaluates {{EXP}}, if it returns #f, {{error}} is applied to {{OBJ ...}},
339else the result of {{EXP}} is returned.
340When compiling in unsafe mode, assertions of this kind are disabled.
341
342
343==== get-call-chain
344
345<procedure>(get-call-chain [START [THREAD]])</procedure>
346
347Returns a list with the call history. Backtrace information is only
348generated in code compiled without {{-no-trace}} and evaluated code.
349If the optional argument {{START}} is given, the backtrace starts at
350this offset, i.e. when {{START}} is 1, the next to last trace-entry is
351printed, and so on. If the optional argument {{THREAD}} is given, then
352the call-chain will only be constructed for calls performed by this
353thread.
354
355
356
357==== print-call-chain
358
359<procedure>(print-call-chain [PORT [START [THREAD [HEADER]]]])</procedure>
360
361Prints a backtrace of the procedure call history to {{PORT}}, which
362defaults to {{(current-output-port)}}. The output is prefixed by the
363{{HEADER}}, which defaults to {{"\n\tCall history:\n"}}.
364
365
366==== procedure-information
367
368<procedure>(procedure-information PROC)</procedure>
369
370Returns an s-expression with debug information for the procedure
371{{PROC}}, or {{#f}}, if {{PROC}} has no associated debug information.
372
373
374==== warning
375
376<procedure>(warning MESSAGE [EXP ...])</procedure>
377
378Displays a warning message (if warnings are enabled with {{enable-warnings}}),
379from the {{MESSAGE}}, and optional {{EXP}} arguments, then continues execution.
380{{MESSAGE}}, and {{EXP}}, may be {{any}} object.
381
382
383=== Lists
384
385==== alist-ref
386
387<procedure>(alist-ref KEY ALIST [TEST [DEFAULT]])</procedure>
388
389Looks up {{KEY}} in {{ALIST}} using {{TEST}} as the comparison function (or {{eqv?}} if
390no test was given) and returns the cdr of the found pair, or {{DEFAULT}} (which defaults to {{#f}}).
391
392
393==== alist-update
394
395<procedure>(alist-update KEY VALUE ALIST [TEST])</procedure>
396<procedure>(alist-update! KEY VALUE ALIST [TEST])</procedure>
397
398If the list {{ALIST}} contains a pair of the form {{(KEY . X)}}, then this procedure
399replaces {{X}} with {{VALUE}} and returns {{ALIST}}. If {{ALIST}} contains no such item, then
400{{alist-update}} returns {{((KEY . VALUE) . ALIST)}}. The optional argument
401{{TEST}} specifies the comparison procedure to search a matching pair in {{ALIST}}
402and defaults to {{eqv?}}. {{alist-update!}} is the destructive version of {{alist-update}}.
403
404
405==== atom?
406
407<procedure>(atom? X)</procedure>
408
409Returns {{#t}} if {{X}} is not a pair.
410
411
412==== butlast
413
414<procedure>(butlast LIST)</procedure>
415
416Returns a fresh list with all elements but the last of {{LIST}}.
417
418
419==== chop
420
421<procedure>(chop LIST N)</procedure>
422
423Returns a new list of sublists, where each sublist contains {{N}}
424elements of {{LIST}}. If {{LIST}} has a length that is not
425a multiple of {{N}}, then the last sublist contains the remaining
426elements.
427
428<enscript highlight=scheme>
429(chop '(1 2 3 4 5 6) 2) ==> ((1 2) (3 4) (5 6))
430(chop '(a b c d) 3) ==> ((a b c) (d))
431</enscript>
432
433
434==== compress
435
436<procedure>(compress BLIST LIST)</procedure>
437
438Returns a new list with elements taken from {{LIST}} with
439corresponding true values in the list {{BLIST}}.
440
441<enscript highlight=scheme>
442(define nums '(99 100 110 401 1234))
443(compress (map odd? nums) nums) ==> (99 401)
444</enscript>
445
446
447==== flatten
448
449<procedure>(flatten LIST1 ...)</procedure>
450
451Returns {{LIST1 ...}} concatenated together, with nested lists
452removed (flattened).
453
454
455==== foldl
456
457<procedure>(foldl PROCEDURE INIT LIST)</procedure>
458
459Applies {{PROCEDURE}} to the elements from {{LIST}}, beginning from
460the left:
461
462<enscript hightlight=scheme>
463(foldl + 0 '(1 2 3)) ==> (+ (+ (+ 0 1) 2) 3)
464</enscript>
465
466Note that the order of arguments taken by {{PROCEDURE}} is different
467from the {{SRFI-1}} {{fold}} procedure, but matches the more natural
468order used in Haskell and Objective Caml.
469
470
471==== foldr
472
473<procedure>(foldr PROCEDURE INIT LIST)</procedure>
474
475Applies {{PROCEDURE}} to the elements from {{LIST}}, beginning from
476the right:
477
478<enscript hightlight=scheme>
479(foldr + 0 '(1 2 3)) ==> (+ 1 (+ 2 (+ 3 0)))
480</enscript>
481
482
483==== intersperse
484
485<procedure>(intersperse LIST X)</procedure>
486
487Returns a new list with {{X}} placed between each element.
488
489
490==== join
491
492<procedure>(join LISTOFLISTS [LIST])</procedure>
493
494Concatenates the lists in {{LISTOFLISTS}} with {{LIST}} placed
495between each sublist. {{LIST}} defaults to the empty list.
496
497<enscript highlight=scheme>
498(join '((a b) (c d) (e)) '(x y)) ==> (a b x y c d x y e)
499(join '((p q) () (r (s) t)) '(-)) ==> (p q - - r (s) t)
500</enscript>
501
502{{join}} could be implemented as follows:
503
504<enscript highlight=scheme>
505(define (join lstoflsts #!optional (lst '()))
506 (apply append (intersperse lstoflists lst)) )
507</enscript>
508
509
510==== rassoc
511
512<procedure>(rassoc KEY LIST [TEST])</procedure>
513
514Similar to {{assoc}}, but compares {{KEY}} with the {{cdr}} of each pair in {{LIST}} using
515{{TEST}} as the comparison procedures (which defaults to {{eqv?}}).
516
517
518==== tail?
519
520<procedure>(tail? X LIST)</procedure>
521
522Returns true if {{X}} is one of the tails (cdr's) of {{LIST}}.
523
524
525=== Vectors
526
527==== vector-copy!
528
529<procedure>(vector-copy! VECTOR1 VECTOR2 [COUNT])</procedure>
530
531Copies contents of {{VECTOR1}} into {{VECTOR2}}. If the
532argument {{COUNT}} is given, it specifies the maximal number of
533elements to be copied. If not given, the minimum of the lengths of the
534argument vectors is copied.
535
536Exceptions: {{(exn bounds)}}
537
538==== vector-resize
539
540<procedure>(vector-resize VECTOR N [INIT])</procedure>
541
542Creates and returns a new vector with the contents of {{VECTOR}} and
543length {{N}}. If {{N}} is greater than the original length of
544{{VECTOR}}, then all additional items are initialized to {{INIT}}. If
545{{INIT}} is not specified, the contents are initialized to some
546unspecified value.
547
548
549==== subvector
550
551<procedure>(subvector VECTOR FROM [TO])</procedure>
552
553Returns a new vector with elements taken from {{VECTOR}} in the
554given range. {{TO}} defaults to {{(vector-length VECTOR)}}.
555
556{{subvector}} was introduced in CHICKEN 4.7.3.
557
558
559=== Combinators
560
561
562==== constantly
563
564<procedure>(constantly X ...)</procedure>
565
566Returns a procedure that always returns the values {{X ...}} regardless of the number and value of its arguments.
567
568<enscript highlight=scheme>
569(constantly X) <=> (lambda args X)
570</enscript>
571
572
573==== complement
574
575<procedure>(complement PROC)</procedure>
576
577Returns a procedure that returns the boolean inverse of {{PROC}}.
578
579<enscript highlight=scheme>
580(complement PROC) <=> (lambda (x) (not (PROC x)))
581</enscript>
582
583
584==== compose
585
586<procedure>(compose PROC1 PROC2 ...)</procedure>
587
588Returns a procedure that represents the composition of the
589argument-procedures {{PROC1 PROC2 ...}}.
590
591<enscript highlight=scheme>
592(compose F G) <=> (lambda args
593 (call-with-values
594 (lambda () (apply G args))
595 F))
596</enscript>
597
598{{(compose)}} is equivalent to {{values}}.
599
600
601==== conjoin
602
603<procedure>(conjoin PRED ...)</procedure>
604
605Returns a procedure that returns {{#t}} if its argument satisfies the
606predicates {{PRED ...}}.
607<enscript highlight=scheme>
608((conjoin odd? positive?) 33) ==> #t
609((conjoin odd? positive?) -33) ==> #f
610</enscript>
611
612
613==== disjoin
614
615<procedure>(disjoin PRED ...)</procedure>
616
617Returns a procedure that returns {{#t}} if its argument satisfies any
618predicate {{PRED ...}}.
619<enscript highlight=scheme>
620((disjoin odd? positive?) 32) ==> #t
621((disjoin odd? positive?) -32) ==> #f
622</enscript>
623
624
625==== each
626
627<procedure>(each PROC ...)</procedure>
628
629Returns a procedure that applies {{PROC ...}} to its arguments, and returns the result(s)
630of the last procedure application. For example
631
632<enscript highlight=scheme>
633(each pp eval)
634</enscript>
635
636is equivalent to
637
638<enscript highlight=scheme>
639(lambda args
640 (apply pp args)
641 (apply eval args) )
642</enscript>
643
644{{(each PROC)}} is equivalent to {{PROC}} and {{(each)}} is equivalent to
645{{void}}.
646
647
648==== flip
649
650<procedure>(flip PROC)</procedure>
651
652Returns a two-argument procedure that calls {{PROC}} with its
653arguments swapped:
654<enscript highlight=scheme>
655(flip PROC) <=> (lambda (x y) (PROC y x))
656</enscript>
657
658
659==== identity
660
661<procedure>(identity X)</procedure>
662
663Returns its sole argument {{X}}.
664
665
666==== list-of?
667
668<procedure>(list-of? PRED)</procedure>
669
670Returns a procedure of one argument that returns {{#t}} when
671applied to a list of elements that all satisfy the predicate procedure
672{{PRED}}, or {{#f}} otherwise.
673
674<enscript highlight=scheme>
675((list-of? even?) '(1 2 3)) ==> #f
676((list-of? number?) '(1 2 3)) ==> #t
677</enscript>
678
679
680==== o
681
682<procedure>(o PROC ...)</procedure>
683
684A single value version of {{compose}} (slightly faster). {{(o)}} is equivalent
685to {{identity}}.
686
687
688=== User-defined named characters
689
690==== char-name
691
692<procedure>(char-name SYMBOL-OR-CHAR [CHAR])</procedure>
693
694This procedure can be used to inquire about character names or to
695define new ones. With a single argument the behavior is as follows:
696If {{SYMBOL-OR-CHAR}} is a symbol, then {{char-name}} returns
697the character with this name, or {{#f}} if no character is defined
698under this name. If {{SYMBOL-OR-CHAR}} is a character, then the
699name of the character is returned as a symbol, or {{#f}} if the
700character has no associated name.
701
702If the optional argument {{CHAR}} is provided, then
703{{SYMBOL-OR-CHAR}} should be a symbol that will be the new name of
704the given character. If multiple names designate the same character,
705then the {{write}} will use the character name that was defined last.
706
707<enscript highlight=scheme>
708(char-name 'space) ==> #\space
709(char-name #\space) ==> space
710(char-name 'bell) ==> #f
711(char-name (integer->char 7)) ==> #f
712(char-name 'bell (integer->char 7))
713(char-name 'bell) ==> #\bell
714(char->integer (char-name 'bell)) ==> 7
715</enscript>
716
717
718=== The unspecified value
719
720==== void
721
722<procedure>(void ARGUMENT ...)</procedure>
723
724Ignores {{ARGUMENT ...}} and returns an unspecified value.
725
726
727=== Continuations
728
729==== call/cc
730
731<procedure>(call/cc PROCEDURE)</procedure>
732
733An alias for {{call-with-current-continuation}}.
734
735This procedure is compatible with the definition from the R7RS
736{{(scheme base)}} library.
737
738=== Symbols
739
740==== Symbol utilities
741
742===== symbol-append
743
744<procedure>(symbol-append SYMBOL1 ...)</procedure>
745
746Creates a new symbol from the concatenated names of the argument symbols
747{{(SYMBOL1 ...)}}.
748
749==== Uninterned symbols ("gensyms")
750
751Symbols may be "interned" or "uninterned". Interned symbols are
752registered in a global table, and when read back from a port are
753identical to a symbol written before:
754
755<enscript highlight=scheme>
756(define sym 'foo)
757
758(eq? sym (with-input-from-string
759 (with-output-to-string
760 (lambda () (write sym)))
761 read))
762
763 => #t
764</enscript>
765
766Uninterned symbols on the other hand are not globally registered and so
767multiple symbols with the same name may coexist:
768
769<enscript highlight=scheme>
770(define sym (gensym 'foo)) ; sym is a uninterned symbol like "foo42"
771
772(eq? sym (with-input-from-string ; the symbol read will be an interned symbol
773 (with-output-to-string
774 (lambda () (write sym)))
775 read))
776
777 => #f
778
779(eq? (string->uninterned-symbol "foo") (string->uninterned-symbol "foo"))
780
781 => #f
782</enscript>
783
784Use uninterned symbols if you need to generate unique values that
785can be compared quickly, for example as keys into a hash-table
786or association list. Note that uninterned symbols lose their
787uniqueness property when written to a file and read back in, as
788in the example above.
789
790===== gensym
791
792<procedure>(gensym [STRING-OR-SYMBOL])</procedure>
793
794Returns a newly created uninterned symbol. If an argument is provided,
795the new symbol is prefixed with that argument.
796
797
798===== string->uninterned-symbol
799
800<procedure>(string->uninterned-symbol STRING)</procedure>
801
802Returns a newly created, unique symbol with the name {{STRING}}.
803
804
805=== Setters
806
807SRFI-17 is fully implemented. For more information see:
808[[http://srfi.schemers.org/srfi-17/srfi-17.html|SRFI-17]].
809
810==== setter
811
812<procedure>(setter PROCEDURE)</procedure>
813
814Returns the setter-procedure of {{PROCEDURE}}, or signals an error if
815{{PROCEDURE}} has no associated setter-procedure.
816
817Note that {{(set! (setter PROC) ...)}} for a procedure that has no
818associated setter procedure yet is a very slow operation (the old
819procedure is replaced by a modified copy, which involves a garbage
820collection).
821
822
823==== getter-with-setter
824
825<procedure>(getter-with-setter GETTER SETTER)</procedure>
826
827Returns a copy of the procedure {{GETTER}} with the associated setter
828procedure {{SETTER}}. Contrary to the SRFI specification, the setter
829of the returned procedure may be changed.
830
831
832=== Binding forms for optional arguments
833
834==== optional
835
836<macro>(optional ARGS DEFAULT)</macro>
837
838Use this form for procedures that take a single optional argument. If
839{{ARGS}} is the empty list {{DEFAULT}} is evaluated and
840returned, otherwise the first element of the list {{ARGS}}. It is
841an error if {{ARGS}} contains more than one value.
842
843<enscript highlight=scheme>
844(define (incr x . i) (+ x (optional i 1)))
845(incr 10) ==> 11
846(incr 12 5) ==> 17
847</enscript>
848
849
850==== case-lambda
851
852<macro>(case-lambda (LAMBDA-LIST1 EXP1 ...) ...)</macro>
853
854Expands into a lambda that invokes the body following the first
855matching lambda-list.
856
857<enscript highlight=scheme>
858(define plus
859 (case-lambda
860 (() 0)
861 ((x) x)
862 ((x y) (+ x y))
863 ((x y z) (+ (+ x y) z))
864 (args (apply + args))))
865
866(plus) ==> 0
867(plus 1) ==> 1
868(plus 1 2 3) ==> 6
869</enscript>
870
871For more information see the documentation for
872[[http://srfi.schemers.org/srfi-16/srfi-16.html|SRFI-16]]
873
874This special form is also compatible with the definition from the R7RS
875{{(scheme case-lambda)}} library.
876
877==== let-optionals
878
879<macro> (let-optionals ARGS ((VAR1 DEFAULT1) ...) BODY ...)</macro>
880
881Binding constructs for optional procedure arguments. {{ARGS}} is
882normally a rest-parameter taken from a lambda-list. {{let-optionals}}
883binds {{VAR1 ...}} to available arguments in parallel, or to
884{{DEFAULT1 ...}} if not enough arguments were provided.
885{{let-optionals*}} binds {{VAR1 ...}} sequentially, so every variable
886sees the previous ones. it is an error if any excess arguments are
887provided.
888
889<enscript highlight=scheme>
890(let-optionals '(one two) ((a 1) (b 2) (c 3))
891 (list a b c) ) ==> (one two 3)
892</enscript>
893
894==== let-optionals*
895
896<macro> (let-optionals* ARGS ((VAR1 DEFAULT1) ... [RESTVAR]) BODY ...)</macro>
897
898Binding constructs for optional procedure arguments. {{ARGS}} is
899normally a rest-parameter taken from a lambda-list. {{let-optionals}}
900binds {{VAR1 ...}} to available arguments in parallel, or to
901{{DEFAULT1 ...}} if not enough arguments were provided.
902{{let-optionals*}} binds {{VAR1 ...}} sequentially, so every variable
903sees the previous ones. If a single variable {{RESTVAR}} is given,
904then it is bound to any remaining arguments, otherwise it is an error
905if any excess arguments are provided.
906
907<enscript highlight=scheme>
908(let-optionals* '(one two) ((a 1) (b 2) (c a))
909 (list a b c) ) ==> (one two one)
910</enscript>
911
912=== Other binding forms
913
914==== and-let*
915
916<macro>(and-let* (BINDING ...) EXP1 EXP2 ...)</macro>
917
918Bind sequentially and execute body. {{BINDING}} can
919be a list of a variable and an expression, a list with a single
920expression, or a single variable. If the value of an expression
921bound to a variable is {{#f}}, the {{and-let*}} form
922evaluates to {{#f}} (and the subsequent bindings and the body
923are not executed). Otherwise the next binding is performed. If
924all bindings/expressions evaluate to a true result, the body is
925executed normally and the result of the last expression is the
926result of the {{and-let*}} form. See also the documentation for
927[[http://srfi.schemers.org/srfi-2/srfi-2.html|SRFI-2]].
928
929==== letrec*
930
931<macro>(letrec* ((VARIABLE EXPRESSION) ...) BODY ...)</macro>
932
933Implements R6RS/R7RS {{letrec*}}. {{letrec*}} is similar to {{letrec}}
934but binds the variables sequentially and is to {{letrec}} what
935{{let*}} is to {{let}}.
936
937This special form is compatible with the definition from the R7RS
938{{(scheme base)}} library.
939
940==== rec
941
942<macro>(rec NAME EXPRESSION)</macro><br>
943<macro>(rec (NAME VARIABLE ...) BODY ...)</macro>
944
945Allows simple definition of recursive definitions. {{(rec NAME EXPRESSION)}} is
946equivalent to {{(letrec ((NAME EXPRESSION)) NAME)}} and {{(rec (NAME VARIABLE ...) BODY ...)}}
947is the same as {{(letrec ((NAME (lambda (VARIABLE ...) BODY ...))) NAME)}}.
948
949==== cut
950
951<macro>(cut SLOT ...)</macro><br>
952<macro>(cute SLOT ...)</macro>
953
954[[http://srfi.schemers.org/srfi-26/srfi-26.html|Syntactic sugar for specializing parameters]].
955
956==== define-values
957
958<macro>(define-values (NAME ...) VALUEEXP)</macro>
959<macro>(define-values (NAME1 ... NAMEn . NAMEn+1) VALUEEXP)</macro>
960<macro>(define-values NAME VALUEEXP)</macro>
961
962Defines several variables at once, with the result values of expression
963{{VALUEEXP}}, similar to {{set!-values}}.
964
965This special form is compatible with the definition from the R7RS
966{{(scheme base)}} library.
967
968==== fluid-let
969
970<macro>(fluid-let ((VAR1 X1) ...) BODY ...)</macro>
971
972Binds the variables {{VAR1 ...}} dynamically to the values {{X1 ...}}
973during execution of {{BODY ...}}. This implements
974[[http://srfi.schemers.org/srfi-15/srfi-15.html|SRFI-15]].
975
976==== let-values
977
978<macro>(let-values (((NAME ...) VALUEEXP) ...) BODY ...)</macro>
979
980Binds multiple variables to the result values of {{VALUEEXP ...}}.
981All variables are bound simultaneously. Like {{define-values}}, the
982{{(NAME ...)}} expression can be any basic lambda list (dotted tail
983notation is supported).
984
985This special form implements
986[[http://srfi.schemers.org/srfi-11/srfi-11.html|SRFI-11]], and it is
987also compatible with the definition from the R7RS {{(scheme base)}}
988library.
989
990
991==== let*-values
992
993<macro>(let*-values (((NAME ...) VALUEEXP) ...) BODY ...)</macro>
994
995Binds multiple variables to the result values of {{VALUEEXP ...}}.
996The variables are bound sequentially. Like {{let-values}}, the
997{{(NAME ...)}} expression can be any basic lambda list (dotted tail
998notation is supported).
999
1000This is also part of
1001[[http://srfi.schemers.org/srfi-11/srfi-11.html|SRFI-11]] and is also
1002compatible with the definition from the R7RS {{(scheme base)}}
1003library.
1004
1005<enscript highlight=scheme>
1006(let*-values (((a b) (values 2 3))
1007 ((p) (+ a b)) )
1008 p) ==> 5
1009</enscript>
1010
1011==== letrec-values
1012
1013<macro>(letrec-values (((NAME ...) VALUEEXP) ...) BODY ...)</macro>
1014
1015Binds the result values of {{VALUEEXP ...}} to multiple variables at
1016once. All variables are mutually recursive. Like {{let-values}}, the
1017{{(NAME ...)}} expression can be any basic lambda list (dotted tail
1018notation is supported).
1019
1020<enscript highlight=scheme>
1021(letrec-values (((odd even)
1022 (values
1023 (lambda (n) (if (zero? n) #f (even (sub1 n))))
1024 (lambda (n) (if (zero? n) #t (odd (sub1 n)))) ) ) )
1025 (odd 17) ) ==> #t
1026</enscript>
1027
1028
1029==== receive
1030
1031<macro>(receive (NAME ...) VALUEEXP BODY ...)</macro><br>
1032<macro>(receive (NAME1 ... NAMEn . NAMEn+1) VALUEEXP BODY ...)</macro><br>
1033<macro>(receive NAME VALUEEXP BODY ...)</macro><br>
1034<macro>(receive VALUEEXP)</macro>
1035
1036[[http://srfi.schemers.org/srfi-8/srfi-8.html|SRFI-8]].
1037Syntactic sugar for {{call-with-values}}. Binds variables
1038to the result values of {{VALUEEXP}} and evaluates {{BODY ...}},
1039similar {{define-values}} but lexically scoped.
1040
1041{{(receive VALUEEXP)}} is equivalent to {{(receive _ VALUEEXP _)}}.
1042This shortened form is not described by SRFI-8.
1043
1044==== set!-values
1045
1046<macro>(set!-values (NAME ...) VALUEEXP)</macro>
1047<macro>(set!-values (NAME1 ... NAMEn . NAMEn+1) VALUEEXP)</macro>
1048<macro>(set!-values NAME VALUEEXP)</macro>
1049
1050Assigns the result values of expression {{VALUEEXP}} to multiple
1051variables, similar to {{define-values}}.
1052
1053==== nth-value
1054
1055<macro>(nth-value N EXP)</macro>
1056
1057Returns the {{N}}th value (counting from zero) of the values returned
1058by expression {{EXP}}.
1059
1060
1061=== Parameters
1062
1063Parameters are CHICKEN's form of dynamic variables, except that they are
1064procedures rather than actual variables. A parameter is a procedure of
1065zero or one arguments. To retrieve the value of a parameter call the
1066parameter-procedure with zero arguments. To change the setting of the
1067parameter, call the parameter-procedure with the new value as argument:
1068
1069<enscript highlight=scheme>
1070(define foo (make-parameter 123))
1071(foo) ==> 123
1072(foo 99)
1073(foo) ==> 99
1074</enscript>
1075
1076Parameters are fully thread-local, each thread of execution
1077owns a local copy of a parameters' value.
1078
1079CHICKEN implements
1080[[http://srfi.schemers.org/srfi-39/srfi-39.html|SRFI-39]], which
1081is also standardized by R7RS.
1082
1083
1084==== parameterize
1085
1086<macro>(parameterize ((PARAMETER1 X1) ...) BODY ...)</macro>
1087
1088Binds the parameters {{PARAMETER1 ...}} dynamically to the values
1089{{X1 ...}} during execution of {{BODY ...}}. (see also:
1090{{make-parameter}} in [[Parameters]]). Note that {{PARAMETER}} may
1091be any expression that evaluates to a parameter procedure.
1092
1093This special form is compatible with the definition from the R7RS
1094{{(scheme base)}} library.
1095
1096==== make-parameter
1097
1098<procedure>(make-parameter VALUE [GUARD])</procedure>
1099
1100Returns a procedure that accepts zero or one argument. Invoking the
1101procedure with zero arguments returns {{VALUE}}. Invoking the
1102procedure with one argument changes its value to the value of that
1103argument and returns the new value (subsequent invocations with zero
1104parameters return the new value). {{GUARD}} should be a procedure of a
1105single argument. Any new values of the parameter (even the initial
1106value) are passed to this procedure. The guard procedure should check
1107the value and/or convert it to an appropriate form.
1108
1109This special form is compatible with the definition from the R7RS
1110{{(scheme base)}} library.
1111
1112=== Substitution forms and macros
1113
1114==== define-constant
1115
1116<macro>(define-constant NAME CONST)</macro>
1117
1118Defines a variable with a constant value, evaluated at compile-time.
1119Any reference to such a constant should appear textually '''after'''
1120its definition. This construct is equivalent to {{define}} when
1121evaluated or interpreted. Constant definitions should only appear at
1122toplevel. Note that constants are local to the current compilation
1123unit and are not available outside of the source file in which they
1124are defined. Names of constants still exist in the Scheme namespace
1125and can be lexically shadowed. If the value is mutable, then the
1126compiler is careful to preserve its identity. {{CONST}} may be any
1127constant expression, and may also refer to constants defined via
1128{{define-constant}} previously, but it must be possible to
1129evaluate the expression at compile-time.
1130
1131==== define-inline
1132
1133<macro>(define-inline (NAME VAR ...) BODY ...)</macro><br>
1134<macro>(define-inline (NAME VAR ... . VAR) BODY ...)</macro><br>
1135<macro>(define-inline NAME EXP)</macro>
1136
1137Defines an inline procedure. Any occurrence of {{NAME}} will be replaced
1138by {{EXP}} or {{(lambda (VAR ... [. VAR]) BODY ...)}}. This is similar
1139to a macro, but variable names and scope are handled correctly.
1140
1141Inline substitutions take place '''after''' macro-expansion, and any
1142reference to {{NAME}} should appear textually '''after''' its
1143definition. Inline procedures are local to the current compilation unit
1144and are not available outside of the source file in which they are
1145defined. Names of inline procedures still exist in the Scheme namespace
1146and can be lexically shadowed. Inline definitions should only appear at
1147the toplevel.
1148
1149Note that the {{inline-limit}} compiler option does not affect inline
1150procedure expansion, and self-referential inline procedures may cause
1151the compiler to enter an infinite loop.
1152
1153In the third form, {{EXP}} must be a lambda expression.
1154
1155This construct is equivalent to {{define}} when evaluated or
1156interpreted.
1157
1158
1159=== Conditional forms
1160
1161==== unless
1162
1163<macro>(unless TEST EXP1 EXP2 ...)</macro>
1164
1165Equivalent to:
1166
1167<enscript highlight=scheme>
1168(if (not TEST) (begin EXP1 EXP2 ...))
1169</enscript>
1170
1171==== when
1172
1173<macro>(when TEST EXP1 EXP2 ...)</macro>
1174
1175Equivalent to:
1176
1177<enscript highlight=scheme>
1178(if TEST (begin EXP1 EXP2 ...))
1179</enscript>
1180
1181
1182=== Record structures
1183
1184==== define-record
1185
1186<macro>(define-record NAME SLOTNAME ...)</macro>
1187
1188Defines a record type. This defines a number of procedures for
1189creating, accessing, and modifying record members.
1190
1191Call {{make-NAME}} to create an instance
1192of the structure (with one initialization-argument for each slot, in
1193the listed order).
1194
1195{{(NAME? STRUCT)}} tests any object for being an instance of this
1196structure.
1197
1198Slots are accessed via {{(NAME-SLOTNAME STRUCT)}}
1199and updated using {{(NAME-SLOTNAME-set!}} {{STRUCT}} {{VALUE)}}.
1200
1201<enscript highlight=scheme>
1202(define-record point x y)
1203(define p1 (make-point 123 456))
1204(point? p1) ==> #t
1205(point-x p1) ==> 123
1206(point-y-set! p1 99)
1207(point-y p1) ==> 99
1208</enscript>
1209
1210===== SRFI-17 setters
1211
1212{{SLOTNAME}} may alternatively also be of the form
1213
1214 (setter SLOTNAME)
1215
1216In this case the slot can be read with {{(NAME-SLOTNAME STRUCT)}} as usual,
1217and modified with {{(set! (NAME-SLOTNAME STRUCT) VALUE)}} (the slot-accessor
1218has an associated SRFI-17 "setter" procedure) instead of
1219the usual {{(NAME-SLOTNAME-set!}} {{STRUCT}} {{VALUE)}}.
1220
1221
1222<enscript highlight=scheme>
1223(define-record point (setter x) (setter y))
1224(define p1 (make-point 123 456))
1225(point? p1) ==> #t
1226(point-x p1) ==> 123
1227(set! (point-y p1) 99)
1228(point-y p1) ==> 99
1229</enscript>
1230
1231==== define-record-type
1232
1233<macro>(define-record-type NAME (CONSTRUCTOR TAG ...) PREDICATE (FIELD ACCESSOR [MODIFIER]) ...)</macro>
1234
1235SRFI-9 record types. For more information see the documentation for
1236[[http://srfi.schemers.org/srfi-9/srfi-9.html|SRFI-9]].
1237
1238As an extension the {{MODIFIER}} may have the form
1239{{(setter PROCEDURE)}}, which will define a SRFI-17 setter-procedure
1240for the given {{PROCEDURE}} that sets the field value.
1241Usually {{PROCEDURE}} has the same name is {{ACCESSOR}} (but it
1242doesn't have to).
1243
1244This special form is also compatible with the definition from the R7RS
1245{{(scheme base)}} library.
1246
1247==== record-printer
1248
1249<procedure>(record-printer NAME)</procedure><br>
1250
1251Returns the procedure used to print records of the type {{NAME}} if
1252one has been set with {{set-record-printer!}}, {{#f}} otherwise.
1253
1254==== set-record-printer!
1255
1256<procedure>(set-record-printer! NAME PROCEDURE)</procedure><br>
1257<procedure>(set! (record-printer NAME) PROCEDURE)</procedure>
1258
1259Defines a printing method for record of the type {{NAME}} by
1260associating a procedure with the record type. When a record of this
1261type is written using {{display, write}} or {{print}}, then
1262the procedure is called with two arguments: the record to be printed
1263and an output-port.
1264
1265<enscript highlight=scheme>
1266(define-record-type foo (make-foo x y z) foo?
1267 (x foo-x)
1268 (y foo-y)
1269 (z foo-z))
1270(define f (make-foo 1 2 3))
1271(set-record-printer! foo
1272 (lambda (x out)
1273 (fprintf out "#,(foo ~S ~S ~S)"
1274 (foo-x x) (foo-y x) (foo-z x))))
1275(define-reader-ctor 'foo make-foo)
1276(define s (with-output-to-string
1277 (lambda () (write f))))
1278s ==> "#,(foo 1 2 3)"
1279(equal? f (with-input-from-string
1280 s read))) ==> #t
1281</enscript>
1282
1283=== Other forms
1284
1285==== include
1286
1287<macro>(include STRING)</macro>
1288
1289Include toplevel-expressions from the given source file in the currently
1290compiled/interpreted program. If the included file has the extension
1291{{.scm}}, then it may be omitted. The file is searched for in the
1292current directory and all directories specified by the {{-include-path}}
1293option.
1294
1295==== include-relative
1296
1297<macro>(include-relative STRING)</macro>
1298
1299Works like {{include}}, but the filename is searched for relative to the
1300including file rather than the current directory.
1301
1302
1303=== Making extra libraries and extensions available
1304
1305==== require-extension
1306
1307<macro>(require-extension ID ...)</macro>
1308
1309This is equivalent to {{(require-library ID ...)}} but performs an implicit
1310{{import}}, if necessary. Since version 4.4.0, {{ID}} may also be an import specification
1311(using {{rename}}, {{only}}, {{except}} or {{prefix}}).
1312
1313To make long matters short - just use {{require-extension}} and it will normally figure everything out for dynamically
1314loadable extensions and core library units.
1315
1316This implementation of {{require-extension}} is compliant with [[http://srfi.schemers.org/srfi-55/srfi-55.html|SRFI-55]]
1317(see the [[http://srfi.schemers.org/srfi-55/srfi-55.html|SRFI-55]] document for more information).
1318
1319
1320==== require-library
1321
1322<macro>(require-library ID ...)</macro>
1323
1324This form does all the necessary steps to make the libraries or extensions given
1325in {{ID ...}} available. It loads syntactic extensions, if needed and generates
1326code for loading/linking with core library modules or separately installed
1327extensions.
1328
1329During interpretation/evaluation {{require-library}} performs one of the
1330following:
1331
1332* If {{ID}} names a built-in feature, then nothing is done.
1333* If {{ID}} names one of the syntactic extensions {{chicken-syntax chicken-ffi-syntax}}, then this extension will be loaded.
1334* If {{ID}} names one of the core library units shipped with CHICKEN, then a {{(load-library 'ID)}} will be performed.
1335* If {{ID}} names an installed extension with the {{syntax}} or {{require-at-runtime}} attribute, then the extensions is loaded at compile-time, probably doing a run-time {{(require ...)}} for any run-time requirements.
1336* Otherwise, {{(require-library ID)}} is equivalent to {{(require 'ID)}}.
1337
1338During compilation, one of the following happens instead:
1339
1340* If {{ID}} names a built-in feature, then nothing is done.
1341* If {{ID}} names one of the syntactic extensions {{chicken-syntax chicken-ffi-syntax}}, then this extension will be loaded at compile-time, making the syntactic extensions available in compiled code.
1342* If {{ID}} names one of the core library units shipped with CHICKEN, or if the option {{-uses ID}} has been passed to the compiler, then a {{(declare (uses ID))}} is generated.
1343* If {{ID}} names an installed extension with the {{syntax}} or {{require-at-runtime}} attribute, then the extension is loaded at compile-time, and code is emitted to {{(require ...)}} any needed run-time requirements.
1344* Otherwise {{(require-library ID)}} is equivalent to {{(require 'ID)}}.
1345
1346{{ID}} should be a pure extension name and should not contain any path prefixes (for example {{dir/lib...}} is illegal).
1347
1348{{ID}} may also be a list that designates an extension-specifier. Currently the following extension specifiers are
1349defined:
1350
1351* {{(srfi NUMBER ...)}} is required for SRFI-55 compatibility and is fully implemented
1352* {{(version ID NUMBER)}} is equivalent to {{ID}}, but checks at compile-time whether the extension named {{ID}} is installed and whether its version is equal or higher than {{NUMBER}}. {{NUMBER}} may be a string or a number, the comparison is done lexicographically (using {{string>=?}}).
1353
1354=== Process shutdown
1355
1356==== emergency-exit
1357
1358<procedure>(emergency-exit [CODE])</procedure>
1359
1360Exits the current process without flushing any buffered output (using
1361the C function {{_exit}}). Note that the {{exit-handler}} is not called
1362when this procedure is invoked. The optional exit status code {{CODE}}
1363defaults to {{0}}.
1364
1365
1366==== exit
1367
1368<procedure>(exit [CODE])</procedure>
1369
1370Exit the running process and return exit-code, which defaults to 0
1371(Invokes {{exit-handler}}).
1372
1373Note that pending {{dynamic-wind}} thunks are ''not'' invoked when exiting your program in this way.
1374
1375
1376=== exit-handler
1377
1378<parameter>(exit-handler)</parameter>
1379
1380A procedure of a single optional argument. When {{exit}} is called,
1381then this procedure will be invoked with the exit-code as argument. The
1382default behavior is to terminate the program.
1383
1384Note that this handler is ''not'' invoked when {{emergency-exit}} is
1385used.
1386
1387
1388=== implicit-exit-handler
1389
1390<parameter>(implicit-exit-handler)</parameter>
1391
1392A procedure of no arguments. When the last toplevel expression of the
1393program has executed, then the value of this parameter is called. The
1394default behaviour is to invoke all pending finalizers.
1395
1396
1397==== on-exit
1398
1399<procedure>(on-exit THUNK)</procedure>
1400
1401Schedules the zero-argument procedures {{THUNK}} to be executed before
1402the process exits, either explicitly via {{exit}} or implicitly after
1403execution of the last top-level form. Note that finalizers for
1404unreferenced finalized data are run before exit procedures.
1405
1406
1407=== System interface
1408
1409
1410==== sleep
1411
1412<procedure>(sleep SECONDS)</procedure>
1413
1414Puts the program to sleep for {{SECONDS}}. If the scheduler is loaded
1415(for example when srfi-18 is in use) then only the calling thread is put
1416to sleep and other threads may continue executing. Otherwise, the whole
1417process is put to sleep.
1418
1419
1420=== Ports
1421
1422==== String ports
1423
1424===== get-output-string
1425
1426<procedure>(get-output-string PORT)</procedure>
1427
1428Returns accumulated output of a port created with
1429{{(open-output-string)}}.
1430
1431
1432===== open-input-string
1433
1434<procedure>(open-input-string STRING)</procedure>
1435
1436Returns a port for reading from {{STRING}}.
1437
1438
1439===== open-output-string
1440
1441<procedure>(open-output-string)</procedure>
1442
1443Returns a port for accumulating output in a string.
1444
1445
1446=== File Input/Output
1447
1448==== flush-output
1449
1450<procedure>(flush-output [PORT])</procedure>
1451
1452Write buffered output to the given output-port. {{PORT}} defaults
1453to the value of {{(current-output-port)}}.
1454
1455=== Port predicates
1456
1457==== input-port-open?
1458
1459<procedure>(input-port-open? PORT)</procedure>
1460
1461Is the given {{PORT}} open for input?
1462
1463<procedure>(output-port-open? PORT)</procedure>
1464
1465Is the given {{PORT}} open for output?
1466
1467==== port-closed?
1468
1469<procedure>(port-closed? PORT)</procedure>
1470
1471Is the given {{PORT}} closed (in all directions)?
1472
1473==== port?
1474
1475<procedure>(port? X)</procedure>
1476
1477Returns {{#t}} if {{X}} is a port object or {{#f}}
1478otherwise.
1479
1480
1481=== Built-in parameters
1482
1483Certain behavior of the interpreter and compiled programs can be
1484customized via the following built-in parameters:
1485
1486==== case-sensitive
1487
1488<parameter>(case-sensitive)</parameter>
1489
1490If true, then {{read}} reads symbols and identifiers in
1491case-sensitive mode and uppercase characters in symbols are printed
1492escaped. Defaults to {{#t}}.
1493
1494
1495==== keyword-style
1496
1497<parameter>(keyword-style)</parameter>
1498
1499Enables alternative keyword syntax, where {{STYLE}} may be either
1500{{#:prefix}} (as in Common Lisp), which recognizes symbols beginning
1501with a colon as keywords, or {{#:suffix}} (as in DSSSL), which recognizes
1502symbols ending with a colon as keywords.
1503Any other value disables the alternative syntaxes. In the interpreter
1504the default is {{#:suffix}}.
1505
1506
1507==== parentheses-synonyms
1508
1509<parameter>(parentheses-synonyms)</parameter>
1510
1511If true, then the list delimiter synonyms {{#\[}} {{#\]}} and {{#\{}} {{#\}}} are enabled. Defaults to {{#t}}.
1512
1513
1514==== symbol-escape
1515
1516<parameter>(symbol-escape)</parameter>
1517
1518If true, then the symbol escape {{#\|}} {{#\|}} is enabled. Defaults to {{#t}}.
1519
1520
1521---
1522Previous: [[Module srfi-4]]
1523
1524Next: [[Module (chicken bitwise)]]